package com.example.shardingjdbcdemo1.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.shardingjdbcdemo1.domain.TOrder;
import com.example.shardingjdbcdemo1.mapper.TOrderMapper;
import com.example.shardingjdbcdemo1.service.ITOrderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements ITOrderService {
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateOrder(Long id, String toAddress) {
        // 强制路由主库
        // HintManager.getInstance().setMasterRouteOnly();
        TOrder order = this.getById(id);
        if (order == null) {
            System.out.println("订单不存在");
            return;
        }
        this.lambdaUpdate().eq(TOrder::getId, id).set(TOrder::getToAddress, toAddress).update();

        order = this.getById(id);
    }
}

